import os
import logging
from logging.handlers import TimedRotatingFileHandler


def set_logging(name=None):
    if not os.path.exists("logs"):
        os.mkdir("logs")
    log_format_str = '[%(asctime)s] p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s'
    formatter = logging.Formatter(log_format_str, '%m-%d %H:%M:%S')
    file_handler = TimedRotatingFileHandler("logs/topic.log", 'D', 1, 0)
    file_handler.suffix = "%Y%m%d.log"
    file_handler.setLevel(logging.INFO)
    file_handler.setFormatter(formatter)
    stream_handler = logging.StreamHandler()
    stream_handler.setLevel(logging.DEBUG)
    stream_handler.setFormatter(formatter)

    log = logging.getLogger(name)
    log.setLevel(logging.INFO)
    log.addHandler(stream_handler)
    log.addHandler(file_handler)


set_logging()
LOGGER = logging.getLogger("topic")
